<?php
//uses("Member");

class SubcategoriesController extends AppController {

  var $helpers = array("Html",'Form',"Text","Javascript","Ajax","Image");
  
  function view($id,$page=1) {
    App::import('Model', 'Product');
    $p = new Product();
    $category = $this->Subcategory->find("Subcategory.subcategory_id = '$id'",null,null,1);
    
    $this->Session->write('go_back',array('','subcategories','view',$id,$page));
    $this->set('cat',$category);
    $this->set('page',$page);
    $this->set('products',$p->c_find("Product.subcategory_id = '$id'"));
    //$this->render();
  }
	
	function add() {
    if ($this->checkSession()) {
      if($this->checkLevel(AUTH_ADMIN)) {// must be admin
      } else {
        $this->notAuth();
      }
    } else {
      $this->forceLogin();
    }
		//pr($this);
		//save new category if there's data
		if (!empty($this->data)) {
			if ($this->Subcategory->save($this->data)) {
				//success!
				$this->Session->setFlash("Subcategory " . $this->data['Subcategory']['subcategory_name'] . " added!");
				$this->redirect('/members/menu');
			}
			foreach($this->form as $t) {
				$s .= $t . "\n";
			}
			$this->Session->setFlash("Error! <pre>" . $s . '</pre');
		}
		$c = new Category();
		$this->set("categories",$c->generateList(null,'category_name',null,'{n}.Category.category_id','{n}.Category.category_name'));
		$this->render();
	}


}

?>
